package com.cn.demo.service.impl;

import com.cn.demo.entity.InternshipLog;
import com.cn.demo.entity.Teacher;
import com.cn.demo.mapper.InternshipLogMapper;
import com.cn.demo.service.InternshipLogService;
import com.cn.demo.service.PageInfoUtilServer;
import com.cn.demo.utils.Result;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class InternshipLogServiceImpl implements InternshipLogService {
    @Autowired
    private InternshipLogMapper internshipLogMapper;

    @Autowired
    private PageInfoUtilServer pageInfoUtilServer;

    @Override
    public Result addInternshipLog(InternshipLog internshipLog) {
        int clockIn = internshipLogMapper.isClockIn(internshipLog.getInternshipId());
        System.out.println(clockIn);
        if (internshipLogMapper.isClockIn(internshipLog.getInternshipId())>0){
            return Result.error("今天已经打卡");
        }else{
            internshipLog.setInternshipLogId(UUID.randomUUID().toString());
            internshipLog.setSubmitDate(new Date());
            System.out.println(internshipLog.toString());
            if (internshipLogMapper.insert(internshipLog)>0) {
                return Result.success();
            }
            return Result.error();
        }
    }

    @Override
    public Result getInternshipLogAll(String studentId, String curriculumInternshipId, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<InternshipLog> internshipLogList  = internshipLogMapper.getInternshipLogAll(studentId,curriculumInternshipId);
        return Result.success(pageInfoUtilServer.currency(internshipLogList));
    }
}